package com.ems.config;

import com.ems.remote.IStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Optional;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 0:47 2023-12-20
 * @return
 */
@Component
public class StrategyFactory {

    @Resource
    private Map<String, IStrategy> map;

    /**
     * 通过帧类型编码查询对应的处理器
     * @param type
     * @return
     */
    public IStrategy getStrategy (String type) {
        IStrategy iStrategy = Optional.ofNullable ( map.get ( type ) ).orElseThrow ( () -> new IllegalArgumentException ( "没有{" + type + "}的请求解析器" ) );
        return iStrategy;
    }

}
